package com.rocksea.app.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.rocksea.app.R;
import com.rocksea.app.fragment.InspeFormItemFragment;
import com.rocksea.app.tasks.QueryPileTask;

import java.util.ArrayList;

/**
 * Created by 吴志华 on 2017/10/26.
 *
 * @FileName:com.rocksea.app.adapter.PileInfoAdapter.java
 */

public class PileInfoAdapter extends RecyclerView.Adapter<PileInfoAdapter.ViewHolder> {

    private ArrayList<String> datas;
    private Context mContext;

    public PileInfoAdapter(ArrayList<String> datas, Context mContext) {
        this.datas = datas;
        this.mContext = mContext;
    }


    @Override
    public PileInfoAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View item = LayoutInflater.from(mContext).inflate(R.layout.inspe_list_item, viewGroup,false);
        return new ViewHolder(item);
    }
    @Override
    public void onBindViewHolder(ViewHolder viewHolder, int i) {
        String index = datas.get(i);
        if (index.contains(QueryPileTask.LABLE))
        {
            String[] infos = index.split(String.format("\\%s",QueryPileTask.LABLE));
            if (infos.length==1)
            {
                viewHolder.mInfo.setText(infos[0]);
                viewHolder.mTitle.setText("");
            }
            else
            {
                viewHolder.mInfo.setText(infos[1]);
                viewHolder.mTitle.setText(infos[0]);
                viewHolder.mInfo.setTextColor(Color.BLACK);
            }

        }
    }
    @Override
    public int getItemCount() {
        return datas.size();
    }
    public static class ViewHolder extends RecyclerView.ViewHolder {
        public TextView mTitle, mInfo;
        public ViewHolder(View view)
        {
            super(view);
            mTitle = (TextView) view.findViewById(R.id.Title);
            mInfo = (TextView) view.findViewById(R.id.Info);
        }
    }

}
